<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" 
      xmlns:sec="http://www.thymeleaf.org/extras/spring-security">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>书籍列表 - 校园二手书交易平台</title>
    <link rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/4.6.0/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/font-awesome/5.15.3/css/all.min.css">
    <style>
        body {
            background-color: #f8f9fa;
        }
        .book-card {
            margin-bottom: 1.5rem;
        }
        .book-image {
            height: 180px;
            object-fit: cover;
        }
        .filter-sidebar {
            background-color: #fff;
            border-radius: 5px;
            padding: 1.25rem;
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
        }
        .filter-title {
            font-size: 1rem;
            margin-bottom: 1rem;
            color: #495057;
        }
        .footer {
            background-color: #343a40;
            color: white;
            padding: 1rem 0;
            margin-top: 2rem;
        }
        .card {
            border: none;
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
            transition: transform 0.2s, box-shadow 0.2s;
        }
        .card:hover {
            transform: translateY(-3px);
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
        }
        .btn {
            border-radius: 3px;
        }
    </style>
</head>
<body>
    <!-- 导航栏 -->
    <nav class="navbar navbar-expand-lg navbar-dark bg-dark">
        <div class="container">
            <a class="navbar-brand" th:href="@{/}">校园二手书交易平台</a>
            <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav">
                <span class="navbar-toggler-icon"></span>
            </button>
            <div class="collapse navbar-collapse" id="navbarNav">
                <ul class="navbar-nav mr-auto">
                    <li class="nav-item">
                        <a class="nav-link" th:href="@{/}"><i class="fas fa-home"></i> 首页</a>
                    </li>
                    <li class="nav-item active">
                        <a class="nav-link" th:href="@{/book/list}"><i class="fas fa-book"></i> 书籍列表</a>
                    </li>
                    <li class="nav-item" sec:authorize="isAuthenticated()">
                        <a class="nav-link" th:href="@{/book/publish}"><i class="fas fa-plus"></i> 发布书籍</a>
                    </li>
                    <li class="nav-item" sec:authorize="isAuthenticated()">
                        <a class="nav-link" th:href="@{/book/my-books}"><i class="fas fa-list"></i> 我的书籍</a>
                    </li>
                </ul>
                <ul class="navbar-nav">
                    <li class="nav-item dropdown" sec:authorize="isAuthenticated()">
                        <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown">
                            <i class="fas fa-user"></i> <span sec:authentication="name"></span>
                        </a>
                        <div class="dropdown-menu dropdown-menu-right">
                            <a class="dropdown-item" th:href="@{/user/profile}"><i class="fas fa-id-card"></i> 个人信息</a>
                            <div class="dropdown-divider"></div>
                            <a class="dropdown-item" th:href="@{/logout}"><i class="fas fa-sign-out-alt"></i> 退出登录</a>
                        </div>
                    </li>
                </ul>
            </div>
        </div>
    </nav>

    <!-- 页面内容 -->
    <div class="container mt-4">
        <div class="row">
            <!-- 右侧书籍列表 -->
            <div class="col-md-12">
                <!-- 标题 -->
                <div class="d-flex justify-content-between align-items-center mb-3">
                    <h4 class="mb-0"><i class="fas fa-book mr-2"></i>书籍列表</h4>
                </div>
                <!-- 搜索框 -->
                <form class="form-inline mb-3" method="get" th:action="@{/book/list}">
                    <input class="form-control mr-2" type="search" name="keyword" placeholder="请输入书名搜索" th:value="${keywordFilter}" style="width: 250px;">
                    <button class="btn btn-outline-success" type="submit"><i class="fas fa-search"></i> 搜索</button>
                </form>
                <!-- 分类和排序功能 -->
                <div class="d-flex justify-content-between align-items-center mb-3">
                    <!-- 分类筛选 -->
                    <div>
                        <a th:href="@{/book/list}" class="btn btn-outline-secondary btn-sm mr-1">全部</a>
                        <a th:href="@{/book/list(category='教材教辅')}" class="btn btn-outline-secondary btn-sm mr-1">教材教辅</a>
                        <a th:href="@{/book/list(category='专业书籍')}" class="btn btn-outline-secondary btn-sm mr-1">专业书籍</a>
                        <a th:href="@{/book/list(category='文学小说')}" class="btn btn-outline-secondary btn-sm mr-1">文学小说</a>
                        <a th:href="@{/book/list(category='考试资料')}" class="btn btn-outline-secondary btn-sm">考试资料</a>
                    </div>
                    <!-- 价格排序 -->
                    <div>
                        <a th:href="@{/book/list(sort='price,asc')}" class="btn btn-outline-primary btn-sm mr-1">
                            价格从低到高
                        </a>
                        <a th:href="@{/book/list(sort='price,desc')}" class="btn btn-outline-primary btn-sm">
                            价格从高到低
                        </a>
                    </div>
                </div>
                
                <!-- 书籍列表 -->
                <div class="row">
                    <div class="col-md-6 col-lg-4 book-card" th:each="book : ${books}">
                        <div class="card h-100">
                            <div class="position-relative">
                                <img th:src="${book.imageUrl != null ? book.imageUrl : '/images/default-book.jpg'}" 
                                     class="card-img-top book-image" alt="Book Cover">
                                <span class="badge badge-pill position-absolute" 
                                      style="top: 10px; right: 10px; font-size: 0.7rem;"
                                      th:classappend="${book.condition == 1 ? 'badge-success' : 
                                                     book.condition == 2 ? 'badge-info' : 
                                                     book.condition == 3 ? 'badge-primary' : 
                                                     book.condition == 4 ? 'badge-warning' : 'badge-danger'}"
                                     th:text="${book.condition == 1 ? '全新' : 
                                             book.condition == 2 ? '优良' : 
                                             book.condition == 3 ? '良好' : 
                                             book.condition == 4 ? '一般' : '较差'}">
                                </span>
                            </div>
                            <div class="card-body d-flex flex-column">
                                <h6 class="card-title font-weight-bold mb-2" th:text="${book.title}">书籍标题</h6>
                                <p class="card-text mb-1 small">
                                    <i class="fas fa-user-edit text-muted small mr-1"></i>
                                    <span class="text-muted" th:text="${book.author}">作者</span>
                                </p>
                                <p class="card-text mb-1 small" th:if="${book.category != null}">
                                    <span class="badge badge-light" th:text="${book.category}"></span>
                                </p>
                                <p class="card-text mt-auto mb-0">
                                    <span class="text-danger font-weight-bold" style="font-size:1.2rem;" th:text="'¥' + ${book.price}">¥价格</span>
                                </p>
                                <form th:action="@{/order/add}" method="post" class="mt-2">
                                    <input type="hidden" name="bookId" th:value="${book.id}" />
                                    <button type="submit" class="btn btn-primary btn-block">
                                        <i class="fas fa-cart-plus mr-1"></i> 添加到我的订单
                                    </button>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
                
                <!-- 无结果提示 -->
                <div class="alert alert-light text-center py-4" th:if="${books == null || books.isEmpty()}">
                    <i class="fas fa-search fa-2x mb-3 text-muted"></i>
                    <p class="mb-0">没有找到符合条件的书籍，请尝试其他搜索条件。</p>
                </div>
            </div>
        </div>
    </div>

    <!-- 页脚 -->
    <footer class="footer py-3">
        <div class="container">
            <div class="row">
                <div class="col-md-6 mb-2 mb-md-0">
                    <p class="mb-0 small">校园二手书交易平台 &copy; 2023</p>
                </div>
                <div class="col-md-6 text-md-right">
                    <a th:href="@{/}" class="text-white small mr-3">首页</a>
                    <a th:href="@{/book/list}" class="text-white small mr-3">书籍列表</a>
                    <a th:href="@{/book/publish}" class="text-white small">发布书籍</a>
                </div>
            </div>
        </div>
    </footer>

    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/4.6.0/js/bootstrap.bundle.min.js"></script>
</body>
</html> 